import 'res/strings.dart';
import 'ui/splash_page/splash_binding.dart';
import 'ui/splash_page/splash_page.dart';
import 'util/keyboard_util.dart';
import 'util/locale_util.dart';
import 'package:flutter/services.dart';

import 'app/app_theme.dart';
import 'routes/routes.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'util/injection_init.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() async {
  await ScreenUtil.ensureScreenSize();
  await Injection.init();

  runApp(GetMaterialApp(
    title: "app名字",
    themeMode: ThemeMode.light,
    getPages: Routes.routePage,
    debugShowCheckedModeBanner: false,
    localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
    ],

    // 主题颜色
    theme: appThemeData,
    initialBinding: SplashBinding(),
    home: const SplashPage(),

    ///国际化支持-来源配置
    translations: Messages(),

    ///国际化支持-默认语言
    locale: LocaleOptions.getDefault(),

    ///国际化支持-备用语言
    fallbackLocale: const Locale('en', 'US'),

    defaultTransition: Transition.rightToLeft,
    builder: (context, child) {
      // 屏幕适配，设定尺寸
      ScreenUtil.init(context, designSize: const Size(390, 844));
      if (Theme.of(context).platform == TargetPlatform.android) {
        // 设置android状态栏为透明
        // MaterialApp组件会覆盖掉这个值。
        SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            statusBarIconBrightness: Brightness.dark);
        SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      }
      return MediaQuery(
          // 设置字体大小不随系统设置改变
          data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
          child: Scaffold(
            resizeToAvoidBottomInset: false,
            body: GestureDetector(
              onTap: () {
                KeyboardUtils.hideKeyboard(context);
              },
              child: child,
            ),
          ));
    },
  ));
}
